home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 18433 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  65 lines

  1. Path: dispatch.news.demon.net!demon!alma.ipso.net
  2. From: martin@ipso.net (Martin Barry)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Q: structures&arrays
  5. Date: Sat, 20 Apr 1996 13:38:57 GMT
  6. Message-ID: <3178e5ce.169129341@news.ipso.net>
  7. References: <4l93s7$9ej@news.inc.net>
  8. Reply-To: martin@ipso.net
  9. NNTP-Posting-Host: alma.ipso.net
  10. X-NNTP-Posting-Host: alma.ipso.net
  11. X-Newsreader: Forte Agent .99e/32.201
  12.  
  13. pendrick@it.uwp.edu (Richard Pendrick) wrote:
  14.  
  15. :  I would appreciate it if someone could enlighten me on why the
  16. below 
  17. :  program errors, and what the correct procedure is for initializing
  18. an 
  19. :  array of a structure.
  20.  
  21. on the intialisation of structures, we may have:
  22. struct point 
  23. {
  24.     int y;
  25.     int x;
  26. };
  27.  
  28. and then initialise, say:
  29.  
  30. struct oint maxpt = {320, 200};
  31.  
  32. that's how you do it!
  33.  
  34. now in your example, i must take a guess that you got mixed up,
  35. because you try to declare an array of type foo, but then try and make
  36. one element of it of type foo.  i think what you wanted was to come
  37. out with was an array type variable.... so how about this?
  38.  
  39. #include <iostream.h>
  40.  
  41. struct foo
  42. {
  43.   char n[30];
  44.   int p;
  45. };
  46.  
  47. int main(void)
  48. {
  49.   struct foo f = { "rick", 1 };   //we declare and intialise  
  50.   cout << f.n << " " <<f.p;    //will print this out for you
  51.  
  52.   return 0;
  53. }
  54.  
  55.  
  56.  
  57. hope that helps
  58.  
  59. llp
  60.  
  61.  
  62. baz
  63.  
  64.  
  65.